package com.iplay.headfirst.chapter2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dangwu
 * @since 2021/3/12 1:26 下午
 */
public class WeatherData implements Subject{
    private List<Observer> observers = new ArrayList<>();
    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        observers.forEach(observer -> observer.update(getMessage()));
    }

    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
